/**
 * Created by easy on 15/5/21.
 */
define(function (){
    var mcfile = {};
    mcfile.getFileExtension = function(filename){
        var filenamelength = filename.split(".").length;
        return filename.split(".")[(filenamelength-1)];
    };
    //参数单位为 Byte
    mcfile.judgeFileSize = function(filesize){//转换文件大小
        var formatfilesize;
        var dotnum;
        var subdot;
        if(filesize >= 0 && filesize < 1024){
            formatfilesize = filesize+' B';
        }else if(filesize >= 1024 && filesize < 1048576){
            filesize = filesize/1024;
            if(filesize.toString().indexOf(".") !== -1){
                dotnum = filesize.toString().split(".")[1].length;
                if(dotnum > 2){
                    filesize = filesize.toFixed(2);
                    subdot = parseInt((filesize.toString().split(".")[1]).substr(0,2));
                    if(subdot === 0){
                        filesize = filesize.toString().split(".")[0];
                    }else if(subdot%10 === 0) {
                        filesize = filesize.toString().split(".")[0]+'.'+(subdot/10);
                    }
                }
            }
            formatfilesize = filesize+' KB';
        }else if(filesize >= 1048576 && filesize < 1073741824){
            filesize = (filesize/1048576);
            if(filesize.toString().indexOf(".") !== -1){
                dotnum = filesize.toString().split(".")[1].length;
                if(dotnum > 2){
                    filesize = filesize.toFixed(2);
                    subdot = parseInt((filesize.toString().split(".")[1]).substr(0,2));
                    if(subdot === 0){
                        filesize = filesize.toString().split(".")[0];
                    }else if(subdot%10 === 0) {
                        filesize = filesize.toString().split(".")[0]+'.'+(subdot/10);
                    }
                }
            }
            formatfilesize = filesize+' MB';
        }else if(filesize >= 1073741824){
            filesize = (filesize/1073741824);
            if(filesize.toString().indexOf(".") !== -1)
            {
                dotnum = filesize.toString().split(".")[1].length;
                if(dotnum > 2){
                    filesize = filesize.toFixed(2);
                    subdot = parseInt((filesize.toString().split(".")[1]).substr(0,2));
                    if(subdot === 0){
                        filesize = filesize.toString().split(".")[0];
                    }else if(subdot%10 === 0) {
                        filesize = filesize.toString().split(".")[0]+'.'+(subdot/10);
                    }
                }
            }
            formatfilesize = filesize+' GB';
        }
        return formatfilesize;
    };
    mcfile.judgeFileType = function(extension){//判断文件类型
        var filetype;
        extension = extension.toLowerCase();
        if(extension === 'doc'||extension === 'docx'||extension === 'wps'){
            filetype = 'word';
        }else if(extension === 'et'||extension === 'xls'||extension === 'xlsx'){
            filetype = 'excel';
        }else if(extension === 'dps'||extension === 'ppt'||extension === 'pptx'){
            filetype = 'powerpoint';
        }else if(extension === 'pdf'){
            filetype = 'pdf';
        }else if(extension === 'png'||extension === 'jpg'||extension === 'jpeg'||extension === 'bmp'||extension === 'gif'||extension === 'tif'){
            filetype = 'image';
        }else if(extension === 'mp3'||extension === 'wav'||extension === 'wma'||extension === 'ogg'||extension === 'aac'){
            filetype = 'sound';
        }else if(extension === 'wmv'||extension === 'avi'||extension === '3gp'||extension === 'flv'||extension === 'mkv'){
            filetype = 'video';
        }else if(extension === 'txt'){
            filetype = 'txt';
        }else if(extension === 'zip'||extension === 'rar'){
            filetype = 'compress';
        }else{
            filetype = 'others';
        }
        return filetype;
    };
    mcfile.shouldOpenVia3rdIniOS = function(extension){
        var isInOthersArr = false;
        var othersArr = ['et','wps','dps','eml','snprt','zip','rar'];
        for(var i = 0; i < othersArr.length; i++){
            if(extension === othersArr[i]){
                isInOthersArr = true;
                break;
            }
        }
        return isInOthersArr;
    };
    return mcfile;
});